/**
 * Set
 */

function Set() {
  let items = {}

  this.add = function(value) {
    if (!this.has(value)) {
      items[value] = value
      return true
    }
    return false
  }

  this.remove = function(value) {
    if (this.has(value)) {
      delete items[value]
      return true
    }
    return false    
  }

  this.has = function(value) {
    return items.hasOwnProperty(value)
    // return value in items
  }

  this.clear = function() {
    items = {}
  }

  this.size = function() {
    // Object.values(items).length
    // Object.assign({}, form) 目标对象会被改变 浅拷贝
    return Object.keys(items).length
  }

  this.values = function() {
    // return Object.values(items)
    // 以下为兼容性写法
    // let arr = []
    // for (const key in items) {
    //   if (items.hasOwnProperty(key)) {
    //     const element = items[key];
    //     arr.push(element)
    //   }
    // }
    // return arr
    return Object.keys(items)
  }
}

let set = new Set()
set.add('I')
set.add('Love')
set.add('Work')
set.remove('Work')
set.add('JAVASCRIPT')
console.log(set.values())